/**
 * 
 */
package lt.vin.exaatto.server;

import java.util.ArrayList;
import java.util.List;

import lt.vin.exaatto.shared.Chat;

import com.google.appengine.api.xmpp.JID;

/**
 * @author Vincentas
 *
 */
public class ChatUtils {

	public static void addMember(Chat chat, JID jid) {
		ParsedJid parsedJid = ParsedJid.parse(jid);
		chat.addMember(parsedJid.getAddress());
	}
	
	public static void removeMember(Chat chat, JID jid) {
		ParsedJid parsedJid = ParsedJid.parse(jid);
		chat.removeMember(parsedJid.getAddress());
	}

	public static List<JID> getMembers(Chat chat) {
		List<JID> result = new ArrayList<JID>();
		
		for (String id : chat.getMembers()) {
			result.add(new JID(id));
		}
		
		return result;
	}	
	
	public static boolean isMember(Chat chat, JID jid) {
		ParsedJid parsedJid = ParsedJid.parse(jid);
		return chat.isMember(parsedJid.getAddress());
	}
}
